<?php

/**
 * Entité modèle : Table des articles
 * Représente l'ensemble des articles disponibles
 * 
 * <b>Structure :</b>
 * <ul>
 *  <li>id</li>
 *  <li>label</li>
 *  <li>title</li>
 *  <li>text</li>
 *  <li>actif</li>
 *  <li>position</li>
 *  <li>rubrique_id/li>
 * </ul>
 * 
 * @author Cyril Souti
 * @version 1.1
 * @package models
 *
 */
class Models_Content_Article extends Models_TableGite
{
	protected $_name = 'content_article';
	protected $_dependentTables = array(Models_Content_ImageArticle::CLASS_NAME);
	protected $_referenceMap = array(self::REFERENCE_RUBRIQUE => array('columns' => 'rubrique_id','refTableClass' => Models_Content_Rubrique::CLASS_NAME,'refColumns' => 'id' ));
	
	const CLASS_NAME = 'Models_Content_Article';
	const REFERENCE_RUBRIQUE = 'Rubrique';
	
	const SQL_CLAUSE_ACTIF = 'actif = ?';
	const SQL_ORDER = 'position ASC';
	

	
	/**
	 * Retourne les articles de la rubrique donnée
	 * 
	 * @param Zend_Db_Table_Row $rubrique
	 * @return array(Zend_Db_Table_Row) des articles
	 */
	public function getArticlesFromRubrique(Zend_Db_Table_Row $rubrique)
	{
		$selectActifs = $this->select()->where(self::SQL_CLAUSE_ACTIF, true)->order(self::SQL_ORDER);
		$articles = $rubrique->findDependentRowset(self::CLASS_NAME, self::REFERENCE_RUBRIQUE, $selectActifs);
		return $articles;
	}
	
	public function getImages(Zend_Db_Table_Row $article)
	{
		$select = $article->select()->order(self::SQL_ORDER);
		$images = $article->findManyToManyRowset(Models_Content_Image::CLASS_NAME, Models_Content_ImageArticle::CLASS_NAME, null, null, $select);
		return $images;
	}
	
	public function getLiens(Zend_Db_Table_Row $article)
	{
		$select = $article->select()->order(self::SQL_ORDER);
		$liens = $article->findManyToManyRowset(Models_Content_Lien::CLASS_NAME, Models_Content_LienArticle::CLASS_NAME, null, null, $select);
		return $liens;
	}
}